<!DOCTYPE html>
<html >
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <title>入群</title>
    <link href="../css/mui.min.css" rel="stylesheet" type="text/css">
    <link href="../css/home.page.css" rel="stylesheet" />
    <link href="../bootstrap-select/bootstrap-select.css" rel="stylesheet">
    <link href="../css/bootstrap.min.css" rel="stylesheet" >
	<link href="../css/mui.picker.min.css" rel="stylesheet" >
    <script charset="UTF-8" src="../js/jquery.min.js"></script>
    <script charset="UTF-8" src="../js/config.js"></script>
    <script charset="UTF-8" src="../js/core.js"></script>
    <script charset="UTF-8" src="../js/cipher-core.js"></script>
    <script charset="UTF-8" src="../js/tripledes.js"></script>
    <script charset="UTF-8" src="../js/mode-ecb.js"></script>
    <script charset="UTF-8" src="../js/zepto.min.js"></script>
    <script charset="UTF-8" src="../js/spin.min.js"></script>
    <script charset="UTF-8" src="../js/mui.min.js"></script>
    <script charset="UTF-8" src="../js/testActivityName.js"></script>
    <script charset="UTF-8" src="../js/simple.tool.js"></script>
	<script charset="UTF-8" src="../js/mui.picker.min.js"></script>
    <style>
        label{
            text-align: right;
        }
        .btn-default{
            border-color: snow;
        }
        .form-control{
            -webkit-box-shadow: inset 0 0px 0px rgba(0,0,0,.075);
        }
        .form-group{
            border-bottom: 1px solid #f6f6f6;max-width: 720px;height: 55px;
        }
    </style>
</head>
<body class="white-bg" >
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" style="width: 95%;" id="form-entering-add" target="ifr">
        <div class="form-group" style="margin-bottom: 0px;border-bottom: 0px solid #f6f6f6;">
            <div class="head-jnx" onclick="record()">
                <img src="../img/fanhui@3x.png" />
                <p>入群</p>
            </div>
        </div>
        <div class="form-group">
            <label class="col-xs-4 control-label"><span style="color: red;font-size: initial;">*</span>牛舍：</label>
            <div class="col-xs-7">
                <select name="cowHouseId" style="/* display: table-cell; */vertical-align: middle;text-align: left;width: 100%;" id="cowHouseId" onchange="getClustering()" required>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-xs-4 control-label"><span style="color: red;font-size: initial;">*</span>分群：</label>
            <div class="col-xs-7">
                <select onclick="inspectNumber()" name="clustering" style="/* display: table-cell; */vertical-align: middle;text-align: left;width: 100%;" id="clustering" required >
					<option value=''>请选择</option>
				</select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-xs-4 control-label"><span style="color: red;font-size: initial;">*</span>耳号：</label>
            <div class="col-xs-7">
                <input name="overbit" class="form-control" type="text" required placeholder="请输入" >
            </div>
        </div>
        <div class="form-group">
            <label class="col-xs-4 control-label"><span style="color: red;font-size: initial;">*</span>出生日期：</label>
            <div class="col-xs-7">
                <div class="input-group date">
                    <!--<span class="input-group-addon"><i class="fa fa-calendar"></i></span>-->
                    <input id="birthDate" type="text" onfocus=this.blur() onclick="dtPicker('birthDate')">
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-xs-4 control-label"><span style="color: red;font-size: initial;">*</span>入群时间：</label>
            <div class="col-xs-7">
                <div class="input-group date">
                    <!--<span class="input-group-addon"><i class="fa fa-calendar"></i></span>-->
                    <input id="sourceTime" type="text" onfocus=this.blur() onclick="dtPicker('sourceTime')">
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-xs-4 control-label">入群来源：</label>
            <div class="col-xs-7">
                <select name="source" style="/* display: table-cell; */vertical-align: middle;text-align: left;width: 100%;" id="source">
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-xs-4 control-label"><span style="color: red;font-size: initial;">*</span>性别：</label>
            <div class="col-xs-7">
                <select name="sex" style="/* display: table-cell; */vertical-align: middle;text-align: left;width: 100%;" required>
                    <option value="" >请选择</option>
                    <option value="0" >公</option>
                    <option value="1" >母</option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-xs-4 control-label">注册号：</label>
            <div class="col-xs-7">
                <input name="registNo" class="form-control" type="text" placeholder="请输入">
            </div>
        </div>
        <div class="form-group">
            <label class="col-xs-4 control-label">毛色：</label>
            <div class="col-xs-7">
                <input name="color" class="form-control" type="text" placeholder="请输入" >
            </div>
        </div>
        <div class="form-group">
            <label class="col-xs-4 control-label">重量：</label>
            <div class="col-xs-7">
                <input name="weight" class="form-control" type="number" min="0" placeholder="单位kg">
            </div>
        </div>
        <div class="form-group">
            <label class="col-xs-4 control-label"><span style="color: red;font-size: initial;">*</span>品种：</label>
            <div class="col-xs-7">
                <select name="variety" style="/* display: table-cell; */vertical-align: middle;text-align: left;width: 100%;" id="variety" required>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-xs-4 control-label">胎次：</label>
            <div class="col-xs-7">
                <input placeholder="请输入" id="parity" name="parity" class="form-control" type="number" min="0" onkeyup="showTime('parity','lastCalveDiv')">
            </div>
        </div>
		 <div class="form-group" id="lastCalveDiv" style="display: none">
            <label class="col-xs-4 control-label"><span style="color: red;font-size: initial;">*</span>最后产犊日期：</label>
            <div class="col-xs-7">
                <div class="input-group date">
                    <!--<span class="input-group-addon"><i class="fa fa-calendar"></i></span>-->
                    <input id="lastCalveDate" name="lastCalveDate" class="form-control" placeholder="yyyy-MM-dd" type="date">
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-xs-4 control-label">配次：</label>
            <div class="col-xs-7">
                <input placeholder="请输入"   id="allocation" name="allocation" class="form-control" type="number" min="0" onkeyup="showTime('allocation','breedDiv')">
            </div>
        </div>
        <div class="form-group" id="breedDiv" style="display: none">
            <label class="col-xs-4 control-label"><span style="color: red;font-size: initial;">*</span>配种日期：</label>
            <div class="col-xs-7">
                <div class="input-group date">
                    <!--<span class="input-group-addon"><i class="fa fa-calendar"></i></span>-->
                    <input id="breedDate" name="breedDate" class="form-control" placeholder="yyyy-MM-dd" type="date">
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-xs-4 control-label">父亲号：</label>
            <div class="col-xs-7">
                <input name="fatherNo" class="form-control" type="text" placeholder="请输入">
            </div>
        </div>
        <div class="form-group">
            <label class="col-xs-4 control-label">母亲号：</label>
            <div class="col-xs-7">
                <input name="motherNo" class="form-control" type="text" placeholder="请输入">
            </div>
        </div>
        <div class="form-group">
            <label class="col-xs-4 control-label">产犊类型：</label>
            <div class="col-xs-7">
                <select name="calveType" style="/* display: table-cell; */vertical-align: middle;text-align: left;width: 100%;" id="calveType">
                </select>
            </div>
        </div>
		<div class="form-group">
            <label class="col-xs-4 control-label">配种员：</label>
            <div class="col-xs-7">
                <select name="breeder" id="breeder" style="/* display: table-cell; */vertical-align: middle;text-align: left;width: 100%;">
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-xs-4 control-label">冻精类型：</label>
            <div class="col-xs-7">
                <select name="semenType" style="/* display: table-cell; */vertical-align: middle;text-align: left;width: 100%;" id="semenType">
                </select>
            </div>
        </div>
        <div class="form-group" style="display: none" id="gestationDateId">
            <label class="col-xs-4 control-label"><span style="color: red;font-size: initial;">*</span>妊娠日期：</label>
            <div class="col-xs-7">
                <div class="input-group date">
                    <input id="gestationDate" name="gestationDate" class="form-control" placeholder="yyyy-MM-dd" type="date">
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-xs-4 control-label">是否已孕：</label>
            <div class="col-xs-7">
                <select id="pregnantState" name="pregnantState" style="/* display: table-cell; */vertical-align: middle;text-align: left;width: 100%;" onchange="showPregnant()">
                    <option value="2">否</option>
                    <option value="1">是</option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-xs-4 control-label">停奶日期：</label>
            <div class="col-xs-7">
                <div class="input-group date">
                    <!--<span class="input-group-addon"><i class="fa fa-calendar"></i></span>-->
                    <input id="stopmilkDate" type="text" onfocus=this.blur() onclick="dtPicker('stopmilkDate')" placeholder="请选择">
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-xs-4 control-label">流产日期：</label>
            <div class="col-xs-7">
                <div class="input-group date">
                    <input id="abortionDate" type="text onfocus=this.blur() onclick="dtPicker('abortionDate')" placeholder="请选择" onchange="changeAbortion()">
                </div>
            </div>
        </div>

        <div class="form-group">
            <label class="col-xs-4 control-label">备注：</label>
            <div class="col-xs-7">
                <input name="remark" class="form-control" type="text" placeholder="请输入">
            </div>
        </div>
        <div class="form-group">
            <div style="width: 320px; margin: auto;">
                <div class="quxiao-btn" style="margin-right: 15px;" onclick="record()">取消</div>
                <input type="submit" value="保存信息" class="quxiao-btn" style="background: #0078fb; color: #FFFFFF;border-radius: 55px;" >
                <div class="clear"></div>
            </div>
        </div>
    </form>
</div>
<iframe name='ifr' id="ifr" style='display: none;'></iframe><!--表单提交防止刷新-->
<script src="../js/bootstrap.min.js"></script>
<script src="../bootstrap-select/bootstrap-select.js"></script>
<script type="text/javascript">
    window.onload=breedLoad();
    function breedLoad() {//获得下拉数据
		var resultData = JSON.parse(localStorage.getItem('addentergroupdata'));
        breedHtml(resultData.data);
		$("#birthDate").val(getDateNow());
		$("#sourceTime").val(getDateNow());
    }
    $("#form-entering-add").submit(function () {
		var parity = $("#parity").val();
		var lastCalveDate = $("#lastCalveDate").val();
		var breedDate = $("#breedDate").val();
		var abortionDate = $("#abortionDate").val();
		var gestationDate = $("#gestationDate").val();
		var allocation = $("#allocation").val();
		if(parity != null && parity != "" && parity != "0"){
			if(lastCalveDate == null || lastCalveDate == ""){
				mui.alert("请填写最后产犊日期！")
				return
			}
		}

		if(allocation != null && allocation != "" && allocation != "0"){
            if(breedDate == null || breedDate == ""){
				mui.alert("请填写配种日期！")
				return
			}
		}

		if(abortionDate != null && abortionDate != ""){
			if(gestationDate == null || gestationDate == ""){
				mui.alert("请填写妊娠日期！")
				return
			}
		}

        map={};
        map=$('#form-entering-add').serializeObject();
        map.url="addentergroup";
        var resultData=ajaxRequestPostSubmit(map);
        if (resultData.head.info == "增加成功") {
            setTimeout(function () {
                record();
            }, 1000);
        }
    });
    function record() {//返回记录
        window.location = "../记录.html";
    }
    function breedHtml(resultData) {//加载下拉
		var userName = resultData.realName;
        var varietyList=resultData.varietyList;//奶牛品种
        loadSelect('variety',varietyList,'code','name','荷斯坦');
        var sourceList=resultData.sourceList;//入群来源
        loadSelect('source',sourceList,'code','name');
        var calveTypeList=resultData.calveTypeList;//产犊类型
        loadSelect('calveType',calveTypeList,'code','name');
        var semenTypeList=resultData.semenTypeList;//冻精类型
        loadSelect('semenType',semenTypeList,'code','name');
        var cowHouseList=resultData.cowHouseList;//牛舍名称
        loadSelect('cowHouseId',cowHouseList,'cowHouseId','cowHouseName');
		var breederList = resultData.breederList;
		loadSelect('breeder',breederList,'real_name','real_name',userName);
        $('.selectpicker').selectpicker('refresh');
    }
    function loadSelect(id,data,code,name,userName) {
        $("#"+id).html("");
        $("#"+id).append("<option value=''>请选择</option>");
        for (i=0;i<data.length;i++){//
			var str='';
			if(userName != null && data[i][name] == userName){
				str='<option value="'+data[i][code]+'" selected>'+data[i][name]+'</option>';
			}else{
				str='<option value="'+data[i][code]+'">'+data[i][name]+'</option>';
			}
            $("#"+id).append(str);
        }
    }
    function getClustering() {//获得分群
        var map={}
        map.url="getClustering";
        map.parent_id=$("#cowHouseId").val();
        var resultData=ajaxRequestPost(map);
        var swarmList=resultData.data.swarmList;
        loadSelect('clustering',swarmList,'cowHouseId','cowHouseName');
        $('.selectpicker').selectpicker('refresh');
    }
	function inspectNumber(){
		var reasonSort = $("#cowHouseId").val();
		var diseaseDetails = $("#clustering").val();
		if((diseaseDetails == null || diseaseDetails == "") && (reasonSort == null || reasonSort == "")){
			mui.toast("请先选择[牛舍]");
		}
	}
	function showTime(str1,str2){
		var name = $("#"+str1).val();
		if(name != null && name != "" && name != "0"){
			$("#"+str2).show();
		}else{
			$("#"+str2).hide();
		}
	}

    function showPregnant() {
            if($("#pregnantState").val() != null && $("#pregnantState").val() != "" && $("#pregnantState").val() != 2 ){
                $("#gestationDateId").show();
            }
            if($("#pregnantState").val() == null || $("#pregnantState").val() == "" || $("#pregnantState").val() == 2 ){
                $("#gestationDateId").hide();
            }
        }

    function changeAbortion() {
        if($("#abortionDate").val() != null && $("#abortionDate").val() != ""){
            $("#pregnantState").val("1");
            showPregnant();
        }else{
            $("#pregnantState").val("2");
            showPregnant();
        }
    }
</script>
</body>
</html>